﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using SQLite.CodeFirst.Console.Entity;

namespace SQLite.CodeFirst.Console
{
    public class FootballDbContext : DbContext
    {
        public FootballDbContext()
            : base("footballDb")
        {
            Configuration.ProxyCreationEnabled = true;
            Configuration.LazyLoadingEnabled = true;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            ConfigureTeamEntity(modelBuilder);
            ConfigureStadionEntity(modelBuilder);

            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            var initializer = new FootballDbInitializer(Database.Connection.ConnectionString, modelBuilder);
            Database.SetInitializer(initializer);
        }

        private static void ConfigureTeamEntity(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Team>();
        }

        private static void ConfigureStadionEntity(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Stadion>();
        }
    }

    public class FootballDbInitializer : SqliteDropCreateDatabaseIfModelChanges<FootballDbContext>
    {
        public FootballDbInitializer(string connectionString, DbModelBuilder modelBuilder)
            : base(connectionString, modelBuilder) { }

        protected override void Seed(FootballDbContext context)
        {
            /*context.Set<Team>().Add(new Team
            {
               
            });*/
        }
    }
}
